/**
 * 获取echarts地图选项数据
 * @param data  桥梁地图数据集合
 * @param bMapOption  地图选项
 */
export const getBridgeMapOption = function(data, bMapOption = {center: [119.618804,31.927062], zoom : 12}, selectedPointData) {
  let bridgePoint = getBridgePointData(data);
  let badBridgePoint = getBadBridgePointData(data);
  return {
    tooltip : {
      trigger: 'item'
    },
    bmap: {
      // 百度地图中心经纬度
      center: bMapOption.center,
      // 百度地图缩放
      zoom: bMapOption.zoom,
      roam: true,
      mapStyle: {
        styleJson:[
          {
            "featureType": "land",
            "elementType": "geometry",
            "stylers": {
              "color": "#e7f7fc"
            }
          },
          {
            "featureType": "water",
            "elementType": "all",
            "stylers": {
              "color": "#96b5d6"
            }
          },
          {
            "featureType": "green",
            "elementType": "all",
            "stylers": {
              "color": "#b0d3dd"
            }
          },
          {
            "featureType": "highway",
            "elementType": "geometry.fill",
            "stylers": {
              "color": "#a6cfcf"
            }
          },
          {
            "featureType": "highway",
            "elementType": "geometry.stroke",
            "stylers": {
              "color": "#7dabb3"
            }
          },
          {
            "featureType": "arterial",
            "elementType": "geometry.fill",
            "stylers": {
              "color": "#e7f7fc"
            }
          },
          {
            "featureType": "arterial",
            "elementType": "geometry.stroke",
            "stylers": {
              "color": "#b0d5d4"
            }
          },
          {
            "featureType": "local",
            "elementType": "labels.text.fill",
            "stylers": {
              "color": "#7a959a"
            }
          },
          {
            "featureType": "local",
            "elementType": "labels.text.stroke",
            "stylers": {
              "color": "#d6e4e5"
            }
          },
          {
            "featureType": "arterial",
            "elementType": "labels.text.fill",
            "stylers": {
              "color": "#374a46"
            }
          },
          {
            "featureType": "highway",
            "elementType": "labels.text.fill",
            "stylers": {
              "color": "#374a46"
            }
          },
          {
            "featureType": "highway",
            "elementType": "labels.text.stroke",
            "stylers": {
              "color": "#e9eeed"
            }
          }
        ]
      }
    },
    series : [
      ...bridgePoint,
      ...badBridgePoint,
      getSelectedPointData(selectedPointData),
      {
        name:'桥梁分类',
        type:'pie',
        radius : '25%',
        center: ['90%', '70%'],
        data:[
          {
            name:"大桥",
            value:data.bridgeCategoryData.filter(c=>c.name === "大桥")[0].value,
            itemStyle:{
              color:getPointColor("大桥")
            }
          },
          {
            name:"中桥",
            value:data.bridgeCategoryData.filter(c=>c.name === "中桥")[0].value,
            itemStyle:{
              color:getPointColor("中桥")
            }
          },
          {
            name:"小桥",
            value:data.bridgeCategoryData.filter(c=>c.name === "小桥")[0].value,
            itemStyle:{
              color:getPointColor("小桥")
            }
          }
        ],
        label: {
          normal: {
            show: false
          },
          emphasis: {
            show: false
          }
        },
        labelLine: {
          normal: {
            show: false
          },
          emphasis: {
            show: false
          }
        },
        itemStyle: {
          normal: {
            color: '#c2bfbb',
            shadowBlur: 200,
            shadowColor: 'rgba(0, 0, 0, 0.5)'
          }
        },
        animationType: 'scale',
        animationEasing: 'elasticOut',
        animationDelay: function (idx) {
          return Math.random() * 200;
        }
      }
    ]
  }
};

function getSelectedPointData(data) {
  return {
    name: '选中桥梁',
    type: 'effectScatter',
    coordinateSystem: 'bmap',
    data: !data ? [] : [{name:data.name, value:[data.longitude, data.latitude, data.value, data.id, data.evaluationType, data.sidePath, data.frontPath, data.point]}],
    symbolSize: function (val) {
      return 30;
      // return (120 - val[2]) / 1.5;
    },
    tooltip:{
      formatter: function (params, ticket, callback) {
        return params.data.name;
      }
    },
    showEffectOn: 'render',
    rippleEffect: {
      brushType: 'stroke'
    },
    hoverAnimation: true,
    label: {
      normal: {
        formatter: '{b}',
        position: 'right',
        show: false
      }
    },
    itemStyle: {
      normal: {
        color: "#3385FF",
        shadowBlur: 15,
        shadowColor: '#333'
      }
    },
    zlevel: 1
  };
}

function getBridgePointData(data) {
  let bridgeCategoryArr = ["大桥", "中桥", "小桥"];
  let results = [];
  bridgeCategoryArr.forEach(c => {
    results.push({
      name: '1、2类桥梁',
      type: 'scatter',
      coordinateSystem: 'bmap',
      data: data.bridgeMapData.filter(d=>d.value < 3 && d.bridgeCategory === c).map(d=>{
        return {name:d.name, value:[d.longitude, d.latitude, d.value, d.id, d.evaluationType, d.sidePath, d.frontPath, d.point]};
      }),
      symbolSize: function (val) {
        return 12;
      },
      tooltip:{
        formatter: function (params, ticket, callback) {
          if (params.data.value[4] === -1) return params.data.name + ": 已进行维修处治，等级为1类";
          else return params.data.name;
        }
      },
      label: {
        normal: {
          formatter: '{b}',
          position: 'right',
          show: false
        },
        emphasis: {
          show: true
        }
      },
      itemStyle: {
        normal: {
          color: getPointColor(c)
        }
      }
    });
  });
  return results;
}

function getBadBridgePointData(data) {
  let bridgeCategoryArr = ["大桥", "中桥", "小桥"];
  let results = [];
  bridgeCategoryArr.forEach(c => {
    results.push({
      name: '三类及以上桥梁',
      type: 'effectScatter',
      coordinateSystem: 'bmap',
      data: data.bridgeMapData.filter(d=>d.value >= 3 && d.bridgeCategory === c).map(d=>{
        return {name:d.name, value:[d.longitude, d.latitude, d.value, d.id, d.evaluationType, d.sidePath, d.frontPath, d.point]};
      }),
      symbolSize: function (val) {
        return 20;
        // return (120 - val[2]) / 1.5;
      },
      tooltip:{
        formatter: function (params, ticket, callback) {
          return params.data.name;
        }
      },
      showEffectOn: 'render',
      rippleEffect: {
        brushType: 'stroke'
      },
      hoverAnimation: true,
      label: {
        normal: {
          formatter: '{b}',
          position: 'right',
          show: false
        }
      },
      itemStyle: {
        normal: {
          color: getPointColor(c),
          shadowBlur: 15,
          shadowColor: '#333'
        }
      },
      zlevel: 1
    });
  });
  return results;
}

function getPointColor(bridgeCategory) {
  switch(bridgeCategory) {
    case "小桥":
      return '#6394ba';
    case "中桥":
      return "#9e56ba";
    case "大桥":
      return "#ba4911";
    default:
      return "#9798de";
  }
}



// WEBPACK FOOTER //
// ./src/assets/js/plugin/map/mapOptions.js